{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "07dde824",
   "metadata": {},
   "source": [
    "---\n",
    "* week07\n",
    "* 2023-11-17\n",
    "* python\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8076a0c0",
   "metadata": {},
   "source": [
    "# 1.书本的知识扩展"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1467d50d",
   "metadata": {},
   "source": [
    "### 1.1 课本实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dea534ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "don't panic!\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "# 第一个小实验\n",
    "phrase = \"don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d7b8174a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第二个小实验\n",
    "for i in range(4):\n",
    "    plist.pop() # pop随机删除\n",
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9aebfa0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'d'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "de36f9a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c63d3b56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'a', 'p']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第三个小实验\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a3ffde0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第四个小实验\n",
    "plist.insert(2,plist.pop(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9e4a2012",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 't', \"'\", ' ', 'a', 'p']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "149a501b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', 't', \"'\", ' ', 'a', 'p']\n",
      "ont' ap\n"
     ]
    }
   ],
   "source": [
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70eaae88",
   "metadata": {},
   "source": [
    "### 1.2列表的切片使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "28f88bfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "list = [1,2,3,4,5,6,7,8,9,10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ecbefe4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, 5, 7, 9]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[0:9:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7b100d7",
   "metadata": {},
   "source": [
    "### 1.3 用切片取出on tap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "23d8cdf8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "don't panic!\n",
      "['d', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "word = \"don't panic!\"\n",
    "plist1 = list(word)\n",
    "print(word)\n",
    "print(plist1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b08d4942",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase = ''.join(plist[1:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1a8a130f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'on'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_phrase # 先取出on"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3ad6d76b",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase = new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]]) # 再单个切片取出每一个字母和空格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2789259e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_phrase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1829592c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
